package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.common.pojo.User;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.dubbo.server.api.HuanXinApi;
import com.tanhua.dubbo.server.pojo.HuanXinUser;
import com.tanhua.server.vo.HuanXinUserVo;
import org.springframework.stereotype.Service;

@Service
public class HuanXinServicer {
    @Reference(version = "1.0.0")
    private HuanXinApi huanXinApi;

    /**
     * 在数据库中查询环信用户的账号密码
     * @return
     */
    public HuanXinUserVo queryHuanXinUser() {
        User user = UserThreadLocal.get();
        HuanXinUser huanXinUser = huanXinApi.queryHuanXinUser(user.getId());
        if (ObjectUtil.isEmpty(huanXinUser)) {
            return null;
        }
        return new HuanXinUserVo(huanXinUser.getUsername(), huanXinUser.getPassword());

    }
}
